/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

Ext.QuickTips.init();
var _pageSize = 20;
var _pageSizeSmall = 10;
var fieldName = ['id', 'name'];
               
var dayFields = [ 'month01', 'month02', 'month03', 'month04', 'month05', 'month06', 'month07', 'month08',"month09"
                   , 'month10', 'month11',"month12"];
               

var fieldLabel = ['ID', '名称'];
var loadServlet = basePath + 'servlet/data/YsjLoad';

var theme = ' 监测点月数据考勤表';
var _title = currentOrgName + theme;
var now = new Date();
var store = null;
function buildWindow() {

    store = new Ext.data.JsonStore({
        url: loadServlet,
        root: 'data',
        idProperty: 'id',
        totalProperty: 'count',
        fields: fieldName.concat(dayFields)
                , baseParams: {lock:lock,cmd:"yTimeCard",yearTo: now.format("Y"),start: 0, limit: _pageSize}
        , autoLoad: true
    });
    function renderer(v, metaData, record, rowIndex, colIndex, store) {
        var value = parseInt(v);
        var imageName;
        if (value > 0) {
            imageName = 'accept.png';
        } else {
            imageName = 'cancel.png';
        } /*else if (value === -10000) {
            imageName = 'lock.png';
        } else {
            imageName = 'lock_delete.png';
        }*/
        return "<image src='" + basePath + "image/icon/" + imageName + "'/>";
    }

    var checkboxSel = new Ext.grid.CheckboxSelectionModel();
    var columns = [];
    columns.push(checkboxSel);
    columns.push({header: fieldLabel[0], sortable: true, dataIndex: fieldName[0], hidden: true});
    columns.push({header: '监测点名称', sortable: true, dataIndex: 'name'});
    for (var i = 1; i <= 12; i++) {       
            columns.push({header: i+"月", dataIndex: dayFields[i-1], width: 60, renderer: renderer});       
    }

    function search() {
        store.reload();
    }

    var grid = new Ext.grid.GridPanel({
        title: _title,
        store: store,
        //selModel:Ext.grid.CellSelectionModel,
        //sm: checkboxSel,
        sm: new Ext.grid.CellSelectionModel(/*{
            listeners: {
                cellselect: function(sm, row, col) {
                    alert("数据：");
                }
            }
        }*/),        
        columns: columns,
        loadMask: true,
        tbar: new Ext.Toolbar([
            pointTypeCombo,
            pointType2Combo,
            voltageLevelCombo,
            reportCombo,
            pointText,
            '-',
            yearToCombo,
            {
                text: "年",
                xtype: 'label'
            },
            '-',            
            searchButton
        ]),
        bbar: new Ext.PagingToolbar({
            pageSize: _pageSize,
            store: store,
            displayInfo: true,
            displayMsg: '显示记录：{0} - {1}   总记录：{2}',
            emptyMsg: "目前没有" + theme + '信息'
        })
    });


    var applicationUI = new Ext.Viewport({
        layout: "fit",
        items: [
            grid
        ]
    });
}
Ext.onReady(buildWindow);
